var cartVisible = false;
  function cart() {
    if(!cartVisible) {
      $(".cart-container").css("display", "block");
      $(".cart-container").animate({"height" : "125px"}, 400);
    } else {
      $(".cart-container").animate({"height" : "0px"}, 400, function(){ $(".cart-container").css("display", "none")});
    }
    cartVisible = !cartVisible;
  }

var onCategory = false;
var onCategories = false;

function category() {
  onCategory = true;
  showCategories();
}

function categories() {
  onCategories = true;
  showCategories();
}

function leftCategory() {
  onCategory = false;
  checkCategories();
}

function leftCategories() {
  onCategories = false;
  checkCategories();
}

function checkCategories() {
  $(".categories-container").hide();
}

function showCategories() {
  $(".categories-container").show();
}

$(document).ready(function() {
  pos = $("#categories").position().left + 2;
  $(".categories-container").css({"left" :  pos + "px"});

  scrollCurrent = 0;
  b = false;
  $(window).scroll(function() {
    if($("body").scrollTop() > 300 || scrollCurrent != 0) {
      $(".top").fadeIn(300);
    } else if(scrollCurrent == 0 && $("body").scrollTop() <= 300) {
      $(".top").fadeOut(300);
    }

    if(scrollCurrent != 0 && $("body").scrollTop() == 0) b = true;
    if(b && $("body").scrollTop() > 400) {
      scrollCurrent = 0;
      $(".top-btn").html("↑ Наверх");
    }
  });
  $(".top").click(function() { 
    if(scrollCurrent == 0) {
      $('html,body').animate({scrollTop: 0}, 700, 'easeInOutQuint');
      scrollCurrent = $("body").scrollTop();
      $(".top-btn").html("↓ Назад");
      b = false;
    } else {
      $('html,body').animate({scrollTop: scrollCurrent}, 700, 'easeInOutQuint');
      scrollCurrent = 0;
      $(".top-btn").html("↑ Наверх");
    }
  });
  

  x = -1;
  var shown = false;
  $(".grid_6_modified").click(function() {
    $(".desc-holder").slideUp();
    $(".desc-bg").slideUp();

    if(shown){
      $(".deal-selected").fadeOut(500);
      shown = false;
    }
    if(x != $(this).data("desc")) {
      descNum = $(this).data("desc");
      $(".desc-holder[data-descholder="+ descNum +"]").slideDown();
      $(".desc-bg", ".desc-holder[data-descholder="+ descNum +"]").slideDown();
      
      x = $(this).data("desc");
    } else {
      x = -1;
    }
    if(!shown){
      $(this).find(".deal-selected").css({display:'block'});  
      shown = true;
    }
    else{
      $(this).find(".deal-selected").fadeOut(500);
    }
  });

  if (window.location.hash.length > 1) {
    page = window.location.hash.split("#")[1];
    scroll(page);
  } else { }

});

function home() {
  window.location = "/";
}

function scroll(dataslide) {
    $('html,body').animate({
      scrollTop: $('h1[data-slide="' + dataslide + '"]').offset().top - 120
    }, 2000, 'easeInOutQuint');
  }

function banner_close() {
  $(".banner").hide(200);
}